package com.aspyn.pong;

import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class PongActivity extends Activity {
    /** Called when the activity is first created. */
	private TextView txtScore;
	private DrawView dv;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        txtScore = (TextView)findViewById(R.id.txtScore);
        
        LinearLayout layout1 = (LinearLayout)findViewById(R.id.layout1);
        
        dv = new DrawView(this, txtScore);
        
        layout1.addView(dv);
    }
    
    //Ball color menu
    public boolean onCreateOptionsMenu(Menu menu) {
    	dv.setGameState(0);
    	Toast.makeText(this, "Game Paused", 1).show();
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.mymenu, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.itemBallBlue:        	
                dv.switchBallColor(Color.BLUE);
                return true;
            case R.id.itemBallGreen:
            	dv.switchBallColor(Color.GREEN);
                return true;
            case R.id.itemBallRed:
            	dv.switchBallColor(Color.RED);
                return true;
            case R.id.itemBallCyan:
            	dv.switchBallColor(Color.CYAN);
                return true;
            case R.id.itemBallYellow:
            	dv.switchBallColor(Color.YELLOW);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    @Override
    public boolean onKeyDown(int keycode, KeyEvent event ) {
     if(keycode == KeyEvent.KEYCODE_MENU){
    	 dv.setGameState(0);//finish code here maybe
     }
     return super.onKeyDown(keycode,event);  
    }
    @Override
    public void onOptionsMenuClosed (Menu menu) {
    	Toast.makeText(this, "Game Resumed", 1).show();
    	
    	dv.setGameState(1);//In case no option is selected but menu is still closed, game must go back into playing mode
    }
    
}